<template>
  <div id="FirstPage">
    <van-nav-bar id="nav" :title="nav_title" left-text="" right-text="按钮" @click-left="onClickLeft"
      @click-right="onClickRight">
      <template #left>
        <van-icon name="arrow-left" size="28" v-if="lastRouter == true" />
      </template>
      <template #right>
        <van-icon name="search" size="28" v-if="lastRouter == true" />
        <van-icon name="setting-o" size="28" v-else-if="lastRouter == false" />
      </template>
      <template #title>
        <van-field v-if="lastRouter == true" label="" v-model="text" left-icon="search" placeholder="请输入关键字" />
        <span v-else-if="lastRouter == false">{{nav_title}}</span>
      </template>
    </van-nav-bar>
    <div class="body">
      <!-- transition：是vue官方的标签，用来包裹一段内容，使包裹的这一段内容产生过度动画效果，name属性用来指定动画的名称 -->
      <transition :name="animateName">
        <router-view />
      </transition>
    </div>
    <TabBar :tabBars="tabBars"></TabBar>
  </div>
</template>

<script>
  //导入TabBar
  import TabBar from '@/components/TabBar.vue'
  export default {
    name: "FirstPage",
    data: function () {
      return {
        tabBars: [{
            className: "icon-elema",
            title: "外卖",
            path: {
              name: 'IndexPage'
            },
          },
          {
            className: "icon-zhinanzhen",
            title: "搜索",
            path: {
              name: 'About'
            },
          },
          {
            className: "icon-liebiao",
            title: "订单",
            path: {
              name: 'Order'
            },
          },
          {
            className: "icon-My",
            title: "我的",
            path: {
              name: 'Login'
            },
          },
        ],
        animateName: "push",
        selectIndex: 0, //该数据源用来记录默认选中的item
        lastRouter: false,
        text: "",
      }
    },
    computed: {
      nav_title() {
        return this.$store.state.nav.title;
      }
    },
    components: {
      TabBar,
    },
    watch: {
      $route: function (to, from) {
        console.log(from);
        if (to.meta.deep > 1) {
          // console.log(to.meta.deep)
          this.lastRouter = true;
        } else {
          // console.log(to.meta.deep)
          this.lastRouter = false;
        }
      }
    },
    methods: {
      onClickLeft() {
        if (this.lastRouter == true) {
          this.$router.go(-1);
        }
      },
      onClickRight() {

      },
    },
  }
</script>

<style lang="less">
  #app {
    font-family: Avenir, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
  }

  #nav {
    z-index: 99;
    width: 100%;
    /* no */
    background-color: #3090e8;
    text-align: center;
    position: fixed;
    left: 0;
    top: 0;
    height: 78px;
  }

  #nav .van-nav-bar__title {
    font-size: 40px;
    color: #fff;
    line-height: 88px;
  }

  .van-field__left-icon .van-icon {
    font-size: 0.6rem !important;
    margin-top: 10px;
    margin-right: 10px;
  }

  .van-nav-bar .van-icon {
    font-size: 0.8rem;
    color: silver !important;
  }

  .van-nav-bar__text {
    color: #fff !important;
  }

  .body {
    padding: 44px 0 48px;
    /* no */
  }

  /* 书写页面过度效果 */
  .push-enter,
  .pop-leave-to,
  .push-leave-to,
  .pop-enter {
    opacity: 0;
  }

  .push-leave-active,
  .push-enter-active,
  .pop-leave-active,
  .pop-enter-active {
    width: 100%;
    transition: all 0.2s linear;
    position: absolute;
    left: 0;
    top: 44px;
    /* no */
  }
</style>